package pers.weiney.mapper;


import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import pers.weiney.pojo.User;

/**
 * @Author: @Weiney
 * @ClassName: UserMapper
 * @Description: 用户数据库层接口
 * @Create: 2024-08-12
 **/
@Mapper
public interface UserMapper {
    /**
     * @param username
     * @return User
     * @author @Weiney
     * @description 根据用户名查找用户
     **/
    @Select("select * from user where username = #{username}")
    User selectByUsername(String username);

    /**
     * @param username
     * @param password
     * @return void
     * @author @Weiney
     * @description 注册用户
     **/
    @Insert("insert into user(username, password, create_time, update_time) " +
            "values(#{username}, #{password}, now(), now()) ")
    void addUser(String username, String password);

    /**
     * @param user
     * @return void
     * @author @Weiney
     * @description 更新用户信息
     **/
    @Update("update user set nickname=#{nickname}, email=#{email}, update_time=#{updateTime} where id=#{id}")
    void updateUser(User user);

    /**
     * @param avatarUrl
     * @return void
     * @author @Weiney
     * @description 更新用户头像
     **/
    @Update("update user set user_pic=#{avatarUrl}, update_time=now() where id=#{id}")
    void updateUserAvatar(String avatarUrl, Integer id);

    /**
     * @param password
     * @param id 
     * @return void
     * @author @Weiney
     * @description 更新用户密码
     **/
    @Update("update user set password=#{password}, update_time=now() where id=#{id}")
    void updateUserPwd(String password, Integer id);
}
